package g2.routemaster.gui.wizards;

import g2.routemaster.gui.BoardSingleton;
import g2.routemaster.model.CityCard;
import g2.routemaster.model.Player;
import g2.routemaster.model.Scoring;
import g2.routemaster.model.TurnManager;

import org.eclipse.jface.wizard.Wizard;

public class ScoringWizard extends Wizard {
   Player player;
   boolean placeCompleted = true;
   boolean dropCompleted = true;
   CityCard[] cityCards;
   CityCard[] dropCards;
      
   public ScoringWizard() {
      super();
      setWindowTitle("Player Scoring");
   }

   public void addPages() {
      addPage(new ScoringPlaceHousesPage());
      addPage(new ScoringDropCardsPage());
   }
   
   public boolean canFinish(){
      return placeCompleted && dropCompleted;
   }

   public boolean performFinish() {
      TurnManager tm = player.getTurnManager();
      tm.startScoring();
      Scoring scoring = tm.getScoring();
      if(cityCards != null && cityCards.length > 0){
         for(CityCard card : cityCards){
         	scoring.addToCityCard(card);
         }
      }
      tm.completeScoring();
      
      if(dropCards != null && dropCards.length > 0){
         for(CityCard card : dropCards){
            tm.discardFromHand(card);
         }
      }
      
      BoardSingleton.instance().updateAll();
      return true;
   }

   public void setPlayer(Player player){
      this.player = player;
      dropCompleted = player.getHand().sizeOfCityCard() <= 3;
   }
}
